const { toUrl,globalData } = getApp();
import { request } from "@/utils/request";
Page({
  toUrl,
  data: {
    list: [],
    page: 1,
    count: 1,
    isExit: false,
    globalData,
    currentIndex:0,
    // typeid:null,
    form:{
      page:1,
      type:0,
    },
    menu:0
  },
  tiaozhuan(e){
    // console.log(e);
    let {ids,url,id} = e.currentTarget.dataset
    if (ids == 0) {
      wx.navigateTo({
        url: `/pages/store/goods/detail?id=${id}`,
      })
    }else{
      wx.navigateTo({
        url: `/pages/me/score/detail?id=${id}`,
      })
    }
  },
  swichTab(e) {
    const index = e.currentTarget.dataset.index;
    if (index == this.data.currentIndex) {
      return;
    }

    const form = this.data.form;
    form.page = 1;
    form.type = index;
    this.setData({
      // menu: index,
      form: form,
      count: 1,
      isExit: false,
      couponList: [],
      currentIndex: index,
      // list:[]
    });
    wx.showLoading({
      title: '加载中...',
      mask: true,
    })
    this.getList();

  },
  getList() {
    // if (this.data.page > 1) {
    //   this.setData({
    //     isExit: true,
    //   });
    //   return;
    // }
    console.log('888888-----');
    const that = this;
    const data = {
      page: this.data.page,
      typeid:this.data.form.type == 0 ? '1':'2' ,//1 店铺 2商品
    };
    request("user/collectlist", { data }).then((res) => {
      if (this.data.page < 2) {
        that.setData({
          list: res.data,
          count: res.count,
          menu:that.data.form.type == 0 ? 0:1

        });
      } else {
          console.log(55554444444,'------');
        that.setData({
          list: that.data.list.concat(res.data),
          count: res.count,
          menu:that.data.form.type == 0 ? 0:1
        });
      }
    }).finally(()=>{
      wx.hideLoading()
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.getList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    //   console.log(1111);
    this.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (isExit) {
      return;
    } else {
        this.setData({
            page:this.data.page + 1
        })
      this.getList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
